﻿using System;

public class FramerInfo : BaseInfo
{
    private int _startFrame;

    private int _endFrame;

    private Action _endCb;

    private Action<int, int> _updateCb;

    /// <summary>
    /// 差帧
    /// </summary>
    private int _diffFrame;

    /// <summary>
    /// 是否可以被移除
    /// </summary>
    private bool _canRemove;

    /// <summary>
    /// 当前帧数
    /// </summary>
    private int _curFrame;

    public override bool CanRemove => _canRemove;

    public FramerInfo(int delayFrame, int startFrame, Action endCb)
    {
        _startFrame = startFrame;
        _endFrame = startFrame + delayFrame;
        _diffFrame = delayFrame;
        _endCb = endCb;
        _updateCb = null;
    }

    public FramerInfo(int delayFrame, int startFrame, Action endCb, Action<int, int> updateCb)
    {
        _startFrame = startFrame;
        _endFrame = startFrame + delayFrame;
        _diffFrame = delayFrame;
        _endCb = endCb;
        _updateCb = updateCb;
    }

    public override void UpdateFrame(int frame)
    {
        _curFrame = frame;
    }

    public override bool CanInvoke()
    {
        return _curFrame > _endFrame;
    }

    public override void Invoke()
    {
        _endCb?.Invoke();
        _canRemove = true;
    }

    public override void InvokeUpdate()
    {
        int elapsedFrame = _curFrame - _startFrame;
        _updateCb?.Invoke(elapsedFrame, _diffFrame);
    }
}
